﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Maticsoft.Common;

namespace Maticsoft.Web.wap
{
    public partial class UserAddrList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Check();
            DeleteItem();
            if (!IsPostBack)
            {
                BindData();
            }
        }

        protected void DeleteItem()
        {
            if (Request.QueryString["act"] == "del")
            {
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    BLL.DeliveryAddr deliBLL = new BLL.DeliveryAddr();
                    Model.DeliveryAddr deliModel = deliBLL.GetModel(int.Parse(Request.QueryString["id"]));
                    deliModel.IsActive = 0;
                    deliModel.UpdateTime = DateTime.Now;
                    deliBLL.Update(deliModel);
                }
            }
        }

        protected void BindData()
        {
            BLL.DeliveryAddr deliBLL = new BLL.DeliveryAddr();
            DataSet ds = deliBLL.GetList("IsActive=1 and UserId=" + this.UserId);
            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();
        }

        protected string GetLocation( object locationId )
        {
            int locId = DigitHelper.GetInt32(locationId);
            BLL.LocationInfo locBLL = new BLL.LocationInfo();
            Model.LocationInfo locModel = locBLL.GetModel(locId);
            if (locModel != null)
            {
                return locModel.pName + " " + locModel.cName;
            }

            return "";
        }
    }
}